<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2018/8/23 0023
 * Time: 15:00
 */
namespace app\admin\model;
use think\Db;

class IntegralModel
{
    /**获取积分变更模型
     * @return $this
     */
    static public function getIntegral($true=true){
        if($true){
            return Db::view('integral_change',true)
                ->view('user','nickname','integral_change.userid=user.id','left')
                ->view('company','company_name','company.id=integral_change.company_id','left')
                ->view('departmen_table','departmen_name','departmen_table.id=integral_change.department_id','left')
                ->view('user',['user.nickname'=>'caozuoren'],'user.id=integral_change.operator');
        }else{
            return Db::view('integral_change',true)
                ->view('user','nickname','integral_change.userid=user.id','left')
                ->view('company','company_name','company.id=integral_change.company_id','left')
                ->view('departmen_table','departmen_name','departmen_table.id=integral_change.department_id','left');
        }
    }

    /**添加积分记录
     * @param $data
     * @return int|string
     */
    static public function addIntegral($data){
        return Db::name('integral_change')->insert($data);
    }

    /**删除积分变更记录
     * @param $field
     * @param null $op
     * @param null $condition
     * @return int
     */
    static public function delIntegral($field, $op = null, $condition = null){
        return Db::name('integral_change')->where($field,$op,$condition)->delete();
    }

    /**更新积分变更记录
     * @param $data
     * @return int|string
     */
    static public function updateIntegral($data){
        return Db::name('integral_change')->update($data);
    }
}